package de.widas.gaesf.xmpp;

import java.io.IOException;
import javax.servlet.http.*;

import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Message;
import com.google.appengine.api.xmpp.MessageBuilder;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;

/**
 * Created on: 19.10.2009, 13:43:23<br/>
 * Copyright 2009 by WidasConcepts GmbH<br/>
 * 
 * @author Meykel Gruel
 */
public class XMPPServlet extends HttpServlet {

	private static final long serialVersionUID = 2690630076507557414L;

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		XMPPService lXMPP = XMPPServiceFactory.getXMPPService();
		Message lMessage = lXMPP.parseMessage(req);
		
		JID lFrom = lMessage.getFromJid();
		String lBody = new StringBuffer().append("Agent: ").append(lMessage.getBody()).toString();
		
		Message lAnswer = new MessageBuilder().withRecipientJids(lFrom).withBody(lBody).build();
		lXMPP.sendMessage(lAnswer);
		resp.setStatus(HttpServletResponse.SC_OK);
	}
}
